QuickTime 4 API Documentation

QuickTime 4 Reference

| Previous | Chapter Contents | Chapter Top | Next |

Sample JavaScript Usage

The following is a simple HTML file that shows four equivalent ways to specify the movie object. In Listing 6, a JavaScript function takes a QuickTime movie and calls its Play() and Stop() methods.

Listing 6  Using JavaScript functions to play and stop a QuickTime movie

<html>
<head>
        <title>Very Simple QuickTime Movie Test</title>
</head>

<script language ="JavaScript">

<!--
        /* a javascript function that takes a QT movie and calls its "Play" method */
        function PlayIt(anObj)
        {
                anObj.Play();
        }
        /* a javascript function that takes a QT movie and calls its "Stop" method */
        function StopIt(anObj)
        {
                anObj.Stop();
        }
//-->

</script>
    <body bgcolor="#ffffff">

                <br>
                This is a test of QuickTime embedded...<br>
                <br>

                <table>
                        <tr>
                                <td width=200>
                    <embed name="movie1" src="yellow_red.mov" width="180" height="160" 
                    bgcolor="black" autoplay="false" enablejavascript="true"> 
                                </td>
                                <td width=200>
                    <embed name="movie2" src="yellow_red.mov" width="180" height="160" 
                    bgcolor="black" autoplay="false" enablejavascript="true"> 
                                </td>
                        </tr>
                        <tr>
                    <td width=200 align=center>this has the name "movie1"</td>
                    <td width=200 align=center>this has the name "movie2"</td>
                        </tr>
                </table>

<br><br>Calling a JavaScript function which takes an object referenced by name<br>
<a href="javascript:PlayIt(document.movie1);">javascript:PlayIt(document.movie1)<a><br>
<a href="javascript:StopIt(document.movie1);">javascript:StopIt(document.movie1)<a><br>
<a href="javascript:PlayIt(document.movie2);">javascript:PlayIt(document.movie2)<a><br>
<a href="javascript:StopIt(document.movie2);">javascript:StopIt(document.movie2)<a><br>

<br>Calling an object (referenced by name) method directly<br>
<a href="javascript:document.movie1.Play();">javascript:document.movie1.Play()</a><br>
<a href="javascript:document.movie1.Stop();">javascript:document.movie1.Stop()</a><br>
<a href="javascript:document.movie2.Play();">javascript:document.movie2.Play()</a><br>
<a href="javascript:document.movie2.Stop();">javascript:document.movie2.Stop()</a><br>

<br>
Calling an object (indexed in the document "embeds" array by index) method directly<br>
<a href="javascript:document.embeds[0].Play();">javascript:document.embeds[0].Play()<a><b>
<a href="javascript:document.embeds[0].Stop();">javascript:document.embeds[0].Stop()<a><b>
<a href="javascript:document.embeds[1].Play();">javascript:document.embeds[1].Play()<a><b>
<a href="javascript:document.embeds[1].Stop();">javascript:document.embeds[1].Stop()<a><b>

<br>
Calling an object (indexed in the document "embeds" array by name) method directly<br>
<a href="javascript:document.embeds['movie1'].Play();">javascript:document.embeds['movie1 ].Play()</a><br>
<a href="javascript:document.embeds['movie1'].Stop();">javascript:document.embeds['movie1'].Stop()</a><br>
<a href="javascript:document.embeds['movie2'].Play();">javascript:document.embeds['movie2'].Play()</a><br>
<a href="javascript:document.embeds['movie2'].Stop();">javascript:document.embeds['movie2'].Stop()</a><br>

        </body>
</html>


© 2000 Apple Computer, Inc.

| Previous | Chapter Contents | Chapter Top | Next |